package com.jcl.elasticsearch.mapper;

import com.jcl.elasticsearch.resume.model.SearchResumePersInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author liuyy
 * @date 2018/11/17
 */
public interface SearchResumePersInfoMapper extends SqlMapper {

    String TABLE_NAME = " search_resume_pers_info ";
    String SQL_INSERT_SUFFIX_ENTITY = "(resume_id, name, sex, mobile, email, birthday, current_address,current_city," +
            "current_salary,salary_start,salary_end,work_year,work_last_position,work_last_company,edu_last_education," +
            "edu_last_school, edu_last_school_tag, edu_last_major) ";
    String SQL_INSERT_SUFFIX_ENTITY_VALUES = "(#{resumeId},#{name},#{sex}," +
            "#{mobile}, #{email}, #{birthday}, #{currentAddress}, #{currentCity}," +
            "#{currentSalary},#{salaryStart},#{salaryEnd},#{workYear},#{workLastPosition}," +
            "#{workLastCompany},#{eduLastEducation},#{eduLastSchool}," +
            "#{eduLastSchoolTag}, #{eduLastMajor})";

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_RESUME_ID,
            SQL_IN,
            FOREACH_START_LIST_RESUME_IDS,
            SQL_PROPERTY_RESUME_ID_VALUE,
            FOREACH_END,
            QUERY_SCRIPT_END
    })
    List<SearchResumePersInfo> findListByResumeIds(@Param("resumeIds") List<Integer> resumeIds);

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_RESUME_ID,
            SQL_EQUAL,
            SQL_PROPERTY_RESUME_ID_VALUE,
            QUERY_SCRIPT_END
    })
    Map<String, Object> findOneMap(@Param("resumeId") Integer resumeId);

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_RESUME_ID,
            SQL_EQUAL,
            SQL_PROPERTY_RESUME_ID_VALUE,
            QUERY_SCRIPT_END
    })
    SearchResumePersInfo findOne(@Param("resumeId") Integer resumeId);

    @Insert({
            QUERY_SCRIPT_START,
            SQL_INSERT,
            SQL_INSERT_VALUE,
            SQL_INSERT_SUFFIX_ENTITY_VALUES,
            QUERY_SCRIPT_END
    })
    int add(SearchResumePersInfo entity);

    @Delete({
            QUERY_SCRIPT_START,
            SQL_DELETE_RESUME_ID,
            SQL_IN,
            FOREACH_START_LIST_RESUME_IDS,
            SQL_PROPERTY_RESUME_ID_VALUE,
            FOREACH_END,
            QUERY_SCRIPT_END
    })
    int batchDeleteByResumeIds(@Param("resumeIds") List<Integer> resumeIds);

    String SQL_INSERT = "insert into " + TABLE_NAME + SQL_INSERT_SUFFIX_ENTITY;
    String SQL_QUERY_RESUME_ID = "select * from " + TABLE_NAME + " where resume_id ";
    String SQL_DELETE_RESUME_ID = "delete from " + TABLE_NAME + " where resume_id ";

}

